﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Utils.Entity;

namespace DCSLibrary
{
    public class CartUI
    {
        public static void AddToCart(CartEntity order,  CartProductEntity orderDetail)
        {
            if (order != null && order.ListProduct != null && order.ListProduct.Count > 0)
            {
                //Tim kiem xem mat hang nay da ton tai trong gio hang chua
                foreach (CartProductEntity prd in order.ListProduct)
                {
                    //Neu co roi thi cong them so luong
                    if (prd.ProductID == orderDetail.ProductID)
                    {
                        prd.Quatnity += orderDetail.Quatnity;
                        return;
                    }
                }
            }
            else
            {
                order.ListProduct.Add(orderDetail);
            }
        }

        public static void RemoveFromCart(CartEntity order, int productId)
        {
            if (order != null &&  order.ListProduct != null && order.ListProduct.Count > 0 )
            {
                //Tim kiem xem mat hang nay da ton tai trong gio hang chua
                foreach (CartProductEntity prd in order.ListProduct)
                {
                    //Neu co roi thi cong them so luong
                    if (prd.ProductID == productId)
                    {
                        order.ListProduct.Remove(prd);
                        return;
                    }
                }
            }
        }

        public static void UpdateCart(CartEntity order, ArrayList listProduct)
        {
            order.ListProduct = listProduct;
        }
    }
}
